﻿using System;
using System.Text;

namespace Xenta.Utils
{
    /// <summary>
    /// Represents the binary helper.
    /// </summary>
    public static class BinaryHelper
    {
        /// <summary>
        /// Converts the array of bytes to its equivalent hex based string representation.
        /// </summary>
        /// <param name="b">An array of bytes.</param>
        /// <returns>The string representation.</returns>
        public static string ToHexString(byte[] b)
        {
            if(b == null || b.Length == 0)
                return String.Empty;
            var sb = new StringBuilder();
            for(int i = 0; i < b.Length; i++)
                sb.Append(b[i].ToString("X2"));
            return sb.ToString();
        }
        /// <summary>
        /// Converts the array of bytes to its equivalent base64 based string representation.
        /// </summary>
        /// <param name="b">An array of bytes.</param>
        /// <returns>The string representation.</returns>
        public static string ToBase64String(byte[] b)
        {
            if(b == null || b.Length == 0)
                return String.Empty;
            return Convert.ToBase64String(b);
        }
    }
}
